/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ventanajuego;

/**
 *
 * @author agu
 */

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.geom.*;

public class Juegador implements Shape {
    private Rectangle2D exterior;
    private RoundRectangle2D interior;
    private Ellipse2D sumidero;

    public Juegador(double x, double y, double w, double h){
        exterior = new Rectangle2D.Double(x, y, w, h);
        interior = new RoundRectangle2D.Double(x+10, y+10, w-20, h-20, 25.0, 25.0);
        sumidero = new Ellipse2D.Double(x+w/2-5, y+15, 10.0, 10.0);
    }

    public void keyReleased(KeyEvent e){

    }

    public void keyPressed(KeyEvent e){

    }

    public boolean contains(Point2D p) {
        return exterior.contains(p);
    }

    public boolean contains(Rectangle2D r) {
        return exterior.contains(r);
    }

    public boolean contains(double x, double y) {
        return exterior.contains(x, y);
    }

    public boolean contains(double x, double y, double w, double h) {
        return exterior.contains(x, y, w, h);
    }

    public Rectangle getBounds() {
        return exterior.getBounds();
    }

    public Rectangle2D getBounds2D() {
        return exterior.getBounds2D();
    }

    public boolean intersects(Rectangle2D r) {
        return exterior.intersects(r);
    }

    public boolean intersects(double x, double y, double w, double h) {
        return exterior.intersects(x, y, w, h);
    }

    public PathIterator getPathIterator(AffineTransform at) {
        return new BañeraPathIterator(at);
    }

    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        return new BañeraPathIterator(at, flatness);
    }

    private enum Parte {EXTERIOR, INTERIOR, SUMIDERO}

    private class BañeraPathIterator implements PathIterator {
        private PathIterator actualIterator;
        private Parte parteActual;
        private boolean hayFlatness;
        private AffineTransform at;
        private double flatness;
        private BañeraPathIterator(){
        parteActual = Parte.EXTERIOR;
    }

    public BañeraPathIterator(AffineTransform at){
        this();
        hayFlatness = false;
        this.at = at;
        actualIterator=exterior.getPathIterator(at);
    }

    public BañeraPathIterator(AffineTransform at, double flatness){
        this();
        hayFlatness = true;
        this.flatness = flatness;
        this.at = at;
        actualIterator=exterior.getPathIterator(at, flatness);
    }

    public int currentSegment(float[] coords) {
        return actualIterator.currentSegment(coords);
    }

    public int currentSegment(double[] coords) {
        return actualIterator.currentSegment(coords);
    }

    public int getWindingRule() {
        return actualIterator.getWindingRule();
    }

    public boolean isDone() {
        if (actualIterator.isDone()){
            switch(parteActual){
                case EXTERIOR : parteActual = Parte.INTERIOR;
                if (hayFlatness)
                    actualIterator = interior.getPathIterator(at, flatness);
                else
                    actualIterator = interior.getPathIterator(at);
                break;
                case INTERIOR : parteActual = Parte.SUMIDERO;
                if (hayFlatness)
                    actualIterator = sumidero.getPathIterator(at, flatness);
                else
                    actualIterator = sumidero.getPathIterator(at);
                break;
            }
        }

    return actualIterator.isDone();
    }

    public void next() {
        actualIterator.next();
    }
    }
}
